package com.study.flyweight.general;

import java.util.HashMap;

public class FlyweightFactory {
    //定义一个容器池
    private static HashMap<String,Flyweight> pool = new HashMap<>();

    //享元工厂
    public static Flyweight getFlyweight(String extrinsic){
        Flyweight flyweight = null;
        if(pool.containsKey(extrinsic)){
            flyweight = pool.get(extrinsic);
            System.out.println("从池中获取对象。。" + extrinsic);
        }else{
            flyweight = new ConcreteFlyweight(extrinsic);
            pool.put(extrinsic,flyweight);
            System.out.println("创建 " + extrinsic + " 并从池中取出---->");
        }
        return flyweight;
    }
}
